package ua.org.nuos.wclientgui.utils;

import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.request.Request;
import ua.org.nuos.sdms.middle.entity.enums.Role;
import ua.org.nuos.sdms.middle.service.AuthenticationLocal;

import javax.ejb.EJB;

/**
 * User: dio
 * Date: 9/16/12
 * Time: 7:31 PM
 */
public class ClientAuthenticatedWebSession extends AbstractAuthenticatedWebSession {

    @EJB(name = "ejb/AuthenticationLocal")
    private AuthenticationLocal authenticationBean;

    /**
     * Construct.
     *
     * @param request The current request object
     */
    public ClientAuthenticatedWebSession(Request request) {
        super(request);
    }

    @Override
    public Roles getRoles() {
        Roles roles = new Roles();
        for (Role role : Role.values()) {
            if (authenticationBean.isUserInRole(role.toString())) {
                roles.add(role.toString());
            }
        }
        return roles;
    }

    @Override
    public boolean isSignedIn() {
        return !getRoles().isEmpty();
    }
}
